<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html style='height:100%;'>
<head>
<base href="<%=basePath%>">

<title>车辆管理</title>

<!-- 图片放大 -->
<script src="js/postbird-img-glass/postbird-img-glass.js"></script>
<style>
.webuploader-container {
	position: relative;
	top: 5px;
}

.right {
	text-align: right
}
</style>
</head>
<script type="text/javascript">
	var carDivCount = 0;
	var fkcustomerId = parent.$("#customerId").val();
	var fkroomId = parent.$("#roomId").val();
	var pid = parent.parent.parent.projectID;
	var historyStatus = parent.$("#historyStatus").val(); //客户是否历史状态
	
	$(function() {
		//初始化表单
		mySubmit("carManageForm", initCarManageData, carManageSuccess);
		//初始化车位使用情况
		var s3 = $("#carportType").select2();
		$("#panel2-1").hide();
		$("#panel2-2").hide();
		//初始化赋值
		initCarMsg();
		initCarportMsg();
		var history = parent.$("#history").val();//是否是历史客户
		if(history == 'yes'){
			//隐藏按钮
			$("#carManageForm #btn_div2").hide();
			$("#carManageForm #btn_div1").hide();
			$("#carManageForm").find("input,textarea").attr("readonly", true);
			$("#carManageForm").find(".addbtn,select,.Wdate").attr("disabled", true);
			$("#carManageForm").find(".icon-fullscreen").hide();
			//上传按钮设置为不能操作
			$("#carManageForm div[id^='filePicker']").hide();
			$("#modifyBtn").remove();
		}
		
	});
	//判断是否提交过审批
	
	var rFileList = new Array(); //
	//设置待删除附件的值到集合中
	function setRFL(id, _this) {
		layer.confirm('删除该图片？', {
			title : '警告',
			icon : 0,
			shade : [ 0.1, '#fff' ]
		}, function() {
			rFileList.push(id);
			//删除指定缩略图
			$("#" + id).remove();
			layer.close(layer.index);
		});
	}
	function imgPlus(data) {
		$("#carManageForm .uploadcancel").css("display", "none");
		$.each(data, function(i, v) {
			//图片放大
			PostbirdImgGlass.init({
				domSelector : "#" + v.id + " img",
				animation : true,
				myDocument : window.parent.parent.parent
			});
		});
	}

	//初始化赋值
	var carNo = new Array(); //存放车牌号
	var isEdit = "no";
	function initCarMsg() {
		$.post("roomInfo/getCarManageList", {
			fkcustomerId : fkcustomerId
			//fkroomId : fkroomId
		}, function(data, status) {
			if (data != null && data.length > 0) {
				isEdit = "yes";
				for (var i = 0; i < data.length; i++) {
					addDiv3(data[i].brandName, data[i].carColor, data[i].carType, 1);
				}
				var $t = $("#carport_1 table");
				for (var i = 0; i < $t.length; i++) {
					v = $t[i];
					$(v).find("input[name='usePeople']").val(data[i].usePeople);
					$(v).find("input[name='carNumber']").val(data[i].carNumber);
					$(v).find("input[name='carInsurance']").val(data[i].carInsurance);
					$(v).find("input[name='drivingLicense']").val(data[i].drivingLicense);
					$(v).find("input[name='steerLicense']").val(data[i].steerLicense);
					$(v).find("input[name='id']").val(data[i].id);
					//$(v).find("select[name='carType']").val(data[i].carType).trigger("change");
					getFileList(data[i].id, "车辆保险", "#list_clbx" + i, setRFL, imgPlus);
					getFileList(data[i].id, "行驶证", "#list_xsz" + i, setRFL, imgPlus);
					getFileList(data[i].id, "驾驶证", "#list_jsz" + i, setRFL, imgPlus);
					carNo.push(data[i].carNumber);
				}
				$("#carManageForm #btn_div2").show();
				$("#carManageForm #btn_div1").hide();
				$("#carManageForm").find("input,textarea").attr("readonly", true);
				$("#carManageForm").find(".addbtn,select,.Wdate").attr("disabled", true);
				$("#carManageForm").find(".icon-fullscreen").hide();
				$("#carManageForm div[id^='filePicker']").hide();
			}
			if (historyStatus == 1) {
			//隐藏按钮
			$("#carManageForm #btn_div2").hide();
			$("#carManageForm #btn_div1").hide();
			$("#carManageForm").find("input,textarea").attr("readonly", true);
			$("#carManageForm").find(".addbtn,select,.Wdate").attr("disabled", true);
			$("#carManageForm").find(".icon-fullscreen").hide();
			//上传按钮设置为不能操作
			$("#carManageForm div[id^='filePicker']").hide();
		}
		});
	}

	var carNum = new Array(); //存储编辑页面车位号集合
	function initCarportMsg() {
		$.post("roomInfo/getCarportList", {
			fkcustomerId : fkcustomerId
			//fkroomId : fkroomId
		}, function(data, status) {
			if (data != null && data.length > 0) {
				isEdit = "yes";
				for (var i = 0; i < data.length; i++) {
					addDiv3('', '', '', 2);
				}
				var $t = $("#carport_2 table");
				for (var i = 0; i < $t.length; i++) {
					v = $t[i];
					$(v).find("input[name='carportLocation']").val(data[i].carportLocation);
					$(v).find("input[name='carportNumber']").val(data[i].carportNumber);
					$(v).find("input[name='priceMsg']").val(data[i].priceMsg);
					$(v).find("input[name='usestaDate']").val(new Date(data[i].usestaDate).format('yyyy-MM-dd'));
					$(v).find("input[name='useendDate']").val(new Date(data[i].useendDate).format('yyyy-MM-dd'));
					$(v).find("b[name='carUseType']").text(data[i].carportType);
					$(v).find("input[name='id']").val(data[i].id);
					carNum.push(data[i].carportNumber);
				}
				$("#carManageForm #btn_div2").show();
				$("#carManageForm #btn_div1").hide();
				$("#carManageForm").find("input,textarea").attr("readonly", true);
				$("#carManageForm").find(".addbtn,select,.Wdate").attr("disabled", true);
				$("#carManageForm").find(".icon-fullscreen").hide();
				$("#carManageForm div[id^='filePicker']").hide();
			}
			if (historyStatus == 1) {
			//隐藏按钮
			$("#carManageForm #btn_div2").hide();
			$("#carManageForm #btn_div1").hide();
			$("#carManageForm").find("input,textarea").attr("readonly", true);
			$("#carManageForm").find(".addbtn,select,.Wdate").attr("disabled", true);
			$("#carManageForm").find(".icon-fullscreen").hide();
			//上传按钮设置为不能操作
			$("#carManageForm div[id^='filePicker']").hide();
		}

		});
	}

	var optCar;
	//optCar操作字段，0：临时保存；1：新增；2：修改
	function saveCar(val) {
		optCar = val;
		if (val == 3) {
			var oldEntityId = fkroomId+","+fkcustomerId;
			$.post("examine/getPendingList", {
				oldEntityId:oldEntityId
			}, function(data, status) {
				if(data!=null && data.length>0){
					layer.msg("该数据已提交过审批，不能重复提交");
				}else{
					//解除锁定状态
					var index = layer.confirm('确定开启编辑状态？', {
						offset : '20%',
						shade : 0
					}, function() {
						//去除只读开启按钮编辑
						$("#carManageForm").find("input,textarea").attr("readonly", false);
						$("#carManageForm").find("select,.addbtn,.Wdate,[type='file']").attr("disabled", false);
						$("#carManageForm").find(".Wdate").attr("readonly", true);
						$("#carManageForm").find(".icon-fullscreen").show();
						$("#carManageForm #modifyBtn").hide();
						$("#carManageForm .hidbtn").addClass("showbtn");
						$("#carManageForm .uploadcancel").show();
						//上传按钮设置为可点击
						$("#carManageForm div[id^='filePicker']").unbind("click").show();
						$("div[id^='filePicker_'] div").css({
							"width" : "60px",
							"height" : "28px"
						});
						$("#carManageForm #changeRemark").show();
						layer.close(index);
					});
				}
			});
		} else {
			$("#carManageForm").submit();
		}
	}
	//初始化车辆品牌下拉框
	var brandSelectList = [];
	function initBrandSelectData(brandName, count) {
		var $s2 = $("#carport_1 select[name='brandName_" + count + "']");
		if (brandSelectList.length == 0) {
			$.getJSON("roomInfo/getCarBrandList", function(data, status) {
				if (status == "success") {
					brandSelectList = data;
					brandInitData($s2, brandName);
				}
			});
		} else {
			brandInitData($s2, brandName);
		}
	}

	function brandInitData($s2, brandName) {
		$.each(brandSelectList, function(i, v) {
			var html1 = "";
			if (v != null && v != "") {
				html1 = "<option value=\"" + v + "\">" + v + "</option>";
				$s2.append(html1);
			}
		});
		//品牌
		$s2.select2({
			tags : true
		});
		if (brandName != "" && brandName != null) {
			$s2.val(brandName).trigger("change");
		}
	}

	//初始化车型下拉框
	var carTypeSelectList = [];
	function initCarTypeSelectData(carType, count) {
		var $s2 = $("#carport_1 select[name='carManType_" + count + "']");
		if (carTypeSelectList.length == 0) {
			$.getJSON("roomInfo/getCarTypeList", function(data, status) {
				if (status == "success") {
					carTypeSelectList = data;
					carTypeInitData($s2, carType);
				}
			});
		} else {
			carTypeInitData($s2, carType);
		}
	}

	function carTypeInitData($s2, carType) {
		$.each(carTypeSelectList, function(i, v) {
			var html1 = "";
			if (v != null && v != "") {
				html1 = "<option value=\"" + v + "\">" + v + "</option>";
				$s2.append(html1);
			}
		});
		//品牌
		$s2.select2({
			tags : true
		});
		if (carType != "" && carType != null) {
			$s2.val(carType).trigger("change");
		}
	}

	//初始化车辆颜色下拉框
	var colorSelectList = [];
	function initColorSelectData(color, count) {
		var $s2 = $("#carport_1 select[name='carColor_" + count + "']");
		if (colorSelectList.length == 0) {
			$.getJSON("roomInfo/getCarColorList", function(data, status) {
				if (status == "success") {
					colorSelectList = data;
					colorInitData($s2, color);
				}
			});
		} else {
			colorInitData($s2, color);
		}
	}

	function colorInitData($s2, color) {
		$.each(colorSelectList, function(i, v) {
			var html1 = "";
			if (v != null && v != "") {
				html1 = "<option value=\"" + v + "\">" + v + "</option>";
				$s2.append(html1);
			}
		});
		//颜色
		$s2.select2({
			tags : true
		});
		if (color != "" && color != null) {
			$s2.val(color).trigger("change");
		}
	}


	var carindex;
	var cn = true; //车位号如果重复该值会为false
	var c = true; //车牌号如果重复该值会为false
	//封装表单数据 
	function initCarManageData() {
		//编辑页面车牌号：用来记录车牌号，以判断是否重复
		var carNoArr = new Array();
		carindex = layer.load(2);
		//车辆信息
		var $table = $("#carport_1 table");
		var carManageList = new Array();
		for (var i = 0; i < $table.length; i++) {
			var v = $table[i];
			var usePeople = $(v).find("input[name='usePeople']").val(); //使用人
			var carType = $(v).find("select[name='carManType_" + i + "']").val(); //车辆类型
			var brandName = $(v).find("select[name='brandName_" + i + "']").val(); //品牌名称
			var carColor = $(v).find("select[name='carColor_" + i + "']").val(); //车辆颜色
			var carNumber = $(v).find("input[name='carNumber']").val(); //车牌号
			var carInsurance = $(v).find("input[name='carInsurance']").val(); //车辆保险
			var drivingLicense = $(v).find("input[name='drivingLicense']").val();
			var steerLicense = $(v).find("input[name='steerLicense']").val();
			var id = $(v).find("input[name='id']").val();
			//车牌号验证
			/* if (!isVehicleNumber(carNumber)) {
				layer.close(carindex);
				if (regString(carNumber)) {
					layer.msg("车牌号不能包含小写字母");
				} else {
					layer.msg("请填写有效车牌号");
				}
				$(v).find("input[name='carNumber']").focus();
				return null;
			} */
			//判断车牌号是否重复
			if (carNoArr.indexOf(carNumber) != -1) {
				layer.close(carindex);
				c = false; //重复 
				layer.msg("车牌号重复了");
				$(v).find("input[name='carNumber']").focus();
				if (!c) {
					c = true;
					return null;
				} else {
					return c;
				}
			}
			carNoArr.push(carNumber);
			var a = checkCarNum(v, id, carNumber, i);
			if (!a) {
				layer.close(carindex);
				$(v).find("input[name='carNumber']").focus();
				layer.msg("该车牌号已存在");
				return null;
			}
			//物件隐藏域值
			var AccessoryCaList = $("#carManage_articleId" + i).val();
			carManageList.push({
				id : id,
				usePeople : usePeople,
				carType : carType,
				brandName : brandName,
				carColor : carColor,
				carNumber : carNumber,
				carInsurance : carInsurance,
				drivingLicense : drivingLicense,
				steerLicense : steerLicense,
				fkCustomer : fkcustomerId,
				fkroomId : fkroomId,
				AccessoryCaList : AccessoryCaList
			})
		}
		//车位使用数据封装
		var $table2 = $("#carport_2 table");
		var carportList = new Array();
		//用来记录车位号，以判断是否重复
		var numArr = new Array();
		for (var i = 0; i < $table2.length; i++) {
			var v = $table2[i];
			var carportLocation = $(v).find("input[name='carportLocation']").val(); //位置
			var carportNumber = $(v).find("input[name='carportNumber']").val(); //车位号
			
			/* if (numArr.indexOf(carportNumber) != -1) { //判断车位号是否重复
				layer.close(carindex);
				cn = false; //重复 
				layer.msg("车位号重复了");
				$(v).find("input[name='carportNumber']").focus();
				if (!cn) {
					cn = true;
					return null;
				} else {
					return cn;
				}
			} */
			var locationAndNum = carportLocation+","+carportNumber;
			if (numArr.indexOf(locationAndNum) != -1) { //判断位置车位号是否重复
				layer.close(carindex);
				cn = false; //重复 
				layer.msg("该位置下车位号重复了");
				$(v).find("input[name='carportNumber']").focus();
				if (!cn) {
					cn = true;
					return null;
				} else {
					return cn;
				}
			}
			numArr.push(locationAndNum);
			var usestaDate = $(v).find("input[name='usestaDate']").val(); //起始时间
			var useendDate = $(v).find("input[name='useendDate']").val(); //结束时间	
			var priceMsg = $(v).find("input[name='priceMsg']").val(); //使用类型
			var carportType = $(v).find("b[name='carUseType']").text(); //使用类型
			var id = $(v).find("input[name='id']").val();
			if (usestaDate == null || usestaDate == "") {
				layer.close(carindex);
				$(v).find("input[name='usestaDate']").focus();
				layer.msg("起始期限不能为空");
				return null;
			} else if (usestaDate > useendDate) {
				layer.close(carindex);
				$(v).find("input[name='usestaDate']").focus();
				layer.msg("起始日期不能大于结束日期");
				return null;
			}
			var r = checkCarportNumber(v, id, carportNumber,carportLocation, i);
			if (!r) {
				layer.close(carindex);
				$(v).find("input[name='carportNumber']").focus();
				layer.msg("该位置车位号已存在");
				return null;
			}
			carportList.push({
				id : id,
				carportLocation : carportLocation,
				carportNumber : carportNumber,
				usestaDate : usestaDate == "" ? null : usestaDate,
				useendDate : useendDate == "" ? null : useendDate,
				carportType : carportType,
				priceMsg : priceMsg,
				fkCustomer : fkcustomerId,
				fkroomId : fkroomId
			})
		}
		var changeRemark = $("#carManageForm [name='changeRemark']").val();
		if (optCar == "2" && changeRemark == "") {
			layer.msg("变更说明不能为空");
			$("#carManageForm [name='changeRemark']").focus();
			layer.close(carindex);
			return null;
		}
		return {
			carManageList : carManageList,
			carportList : carportList,
			opt : optCar,
			delcarManIds : delcarManIds, //需要删除的车辆管理id数组
			delcarportIds : delcarportIds, //需要删除的车位使用id数组
			rFileList : rFileList, //要删除的id数组
			changeRemark : changeRemark,
			fkCustomer : fkcustomerId,
			fkroomId : fkroomId
		};
	}


	//上传成功回调
	function carManageSuccess(data, status) {
		layer.close(carindex);
		if (status == "success") {
			layer.alert("保存成功！", {
				offset : '20%',
				shade : [ 0.1, '#fff' ]
			}, function() {
				location.reload();
				layer.close(carindex);
			});
		} else {
			layer.alert('保存失败！');
		}
	}
	//验证车牌号是否唯一
	function checkCarNum(v, id, val, i) {
		var flag = false; //已存在,拦截
		var url = "roomInfo/checkCarNum";
		if (c) { //页面验证通过
			$.ajaxSettings.async = false; //同步执行
			if (id == "" || id == undefined) { //新添加的数据
				$.getJSON(url, {
					carNumber : val
				}, function(data, status) {
					if (status == "success") {
						if (data.length > 0) {
							flag = false; //已存在，拦截
						} else {
							flag = true; //不存在，不拦截
						}
					}
				});
			} else { //编辑的数据
				console.log(carNo[i]+"===");
				if (carNo[i] == val) {
					flag = true; //编辑未修改，不拦截
				} else {
					$.getJSON(url, {
						carNumber : val
					}, function(data, status) {
						if (status == "success") {
							if (data.length > 0) {
								if (data[0].carNumber == val && data[0].id == id) {
									flag = true; //未修改的数据
								}else{
									flag = false; //未修改的数据
								}
							} else {
								flag = true; //，不拦截
							}
						}
					});
				}
			}
		} else { //页面验证不通过
			flag = false; //已存在，拦截
		}
		return flag;
	}

	//验证车位号是否唯一
	function checkCarportNumber(v, id, val,carportLocation, i) {
		var flag = false; //已存在,拦截
		var url = "roomInfo/checkCarportNumber";
		if (cn) { //页面验证通过
			$.ajaxSettings.async = false; //同步执行
			if (id == "" || id == undefined) { //新添加的数据
				$.getJSON(url, {
					carportNumber : val,
					pid : pid,
					carportLocation:carportLocation
				}, function(data, status) {
					if (status == "success") {
						if (data.length > 0) {
							flag = false; //已存在，拦截
						} else {
							flag = true; //不存在，不拦截
						}
					}
				});
			} else { //编辑的数据
				$.getJSON(url, {
					carportNumber : val,
					pid : pid
				}, function(data, status) {
					if (status == "success") {
						if (data.length > 0) {
							if (carNum[i] == val) {
								flag = true; //编辑未修改，不拦截
							} else {
								flag = false; //已存在，拦截
							}
						} else {
							flag = true; //，不拦截
						}
					}
				});
			}
		} else { //页面验证不通过
			flag = false; //已存在，拦截
		}
		return flag;
	}
</script>
<body>
	<form class="cmxform" id="carManageForm" method="post"
		action="roomInfo/addCarManage" onsubmit="return false;">
		<div style="padding:0px">
			<div class="panel panel-default">
				<div class="panel-body">
					<!-- 车辆信息start -->
					<div id="carport_1">
						<p class="style_border_bottom">
							<span class="style_btn">车辆信息</span> <span class="style_input">&nbsp;&nbsp;
								<a class="btn btn-danger radius a_font addbtn"
								onclick="addDiv3('','','','1')" > 添加</a>
							</span>
						</p>

					</div>
					<!-- 车辆信息end -->

					<!-- 车位使用情况start -->
					<div id="carport_2">
						<p class="style_border_bottom">
							<span class="style_btn">车位使用情况</span> <strong width="100"
								style="margin:0px 10px 0px 20px">车位使用情况</strong> <select
								class="js-example-basic-single" name="carportType"
								id="carportType" style="width:160px;">
								<option value="租赁:直租">租赁:直租</option>
								<option value="租赁:转租">租赁:转租</option>
								<option value="购买">购买</option>
							</select> <span class="style_input">&nbsp;&nbsp; <a
								class="btn btn-danger radius a_font addbtn"
								onclick="addDiv3('','','','2')" > 添加</a>
							</span>
						</p>
					</div>
					<!-- 车位使用情况end -->
					<div id="changeRemark" hidden="hidden">
						<span
							style="display: inline-block;width: 90px;text-align: center;">变更说明</span>
						<textarea rows="3" cols="70" style="width: 65%"
							name="changeRemark"></textarea>
						<span style="color:red"> *</span>
					</div>

				</div>
			</div>
			<div style="width:100%;text-align:center; padding-top:20px">
				<div id="btn_div1" >
					<button class="btn btn-danger radius my-btn" onclick="saveCar(0)"
						type="button">提交</button>
					<button class="btn btn-danger radius my-btn" onclick="saveCar(1)"
						type="button">保 存</button>
					<a class="btn btn-default radius"
						onClick="resetForms('carManageForm');"> 重置 </a> <br />
				</div>
				<div id="btn_div2" style="display:none;">
					<shiro:hasPermission name="permission:edit">
						<button id="modifyBtn" type="button"
							class="btn btn-danger radius my-btn" onclick="saveCar(3)">启用编辑</button>
						<button class="btn btn-danger radius my-btn hidbtn"
							onclick="saveCar(2)" type="button">保存修改</button>
						<a class="btn btn-default radius hidbtn"
							onClick="resetForms('carManageForm');"> 重置 </a>
					</shiro:hasPermission>
				</div>
			</div>
		</div>
		<div style="display:none">
			<input type="hidden" name="roomId" id="roomId" value=" " /> <input
				type="hidden" name="projectName" id="projectName" value="" /> <input
				type="hidden" name="projectId" id="projectId" value="" />
		</div>
	</form>
	<script type="text/javascript">
		$(function() {
			$("div[id^='filePicker_']").css({"display":"inline-block","vertical-align":"bottom"});
		
		});
		//上传成功回调
		function carSuccess(file, response) {
			//alert("上传成功回调");
			PostbirdImgGlass.init({
				domSelector : "td img",
				animation : true,
				//height : '80%',
				myDocument : window.parent.parent.parent
			});
		}
		//上传失败回调
		function carErr(file, data) {
			//alert("上传失败回调");
		}
	
		//添加模板div
		function addDiv3(brandName, carColor, carType, i) {
			var node;
			//车辆信息
			if (i == 1) {
				//修改附件id 缩略图id 和隐藏域id
				if (carDivCount == 0) {
					$("#cm_template").find("select[name='brandName']").attr("name", "brandName_" + carDivCount);
					$("#cm_template").find("select[name='carColor']").attr("name", "carColor_" + carDivCount);
					$("#cm_template").find("select[name='carManType']").attr("name", "carManType_" + carDivCount);
					$("#cm_template #filePicker_clbx").attr('id', "filePicker_clbx" + carDivCount);
					$("#cm_template #list_clbx").attr('id', "list_clbx" + carDivCount);
					$("#cm_template #carManage_articleId").attr('id', "carManage_articleId" + carDivCount);
					$("#cm_template #filePicker_xsz").attr('id', "filePicker_xsz" + carDivCount);
					$("#cm_template #list_xsz").attr('id', "list_xsz" + carDivCount);
					$("#cm_template #filePicker_jsz").attr('id', "filePicker_jsz" + carDivCount);
					$("#cm_template #list_jsz").attr('id', "list_jsz" + carDivCount);
				} else {
					$("#cm_template").find("select[name='brandName_" + (carDivCount - 1) + "']").attr("name", "brandName_" + carDivCount);
					$("#cm_template").find("select[name='carColor_" + (carDivCount - 1) + "']").attr("name", "carColor_" + carDivCount);
					$("#cm_template").find("select[name='carManType_" + (carDivCount - 1) + "']").attr("name", "carManType_" + carDivCount);
					$("#cm_template #filePicker_clbx" + (carDivCount - 1)).attr('id', "filePicker_clbx" + carDivCount);
					$("#cm_template #list_clbx" + (carDivCount - 1)).attr('id', "list_clbx" + carDivCount);
					$("#cm_template #carManage_articleId" + (carDivCount - 1)).attr('id', "carManage_articleId" + carDivCount);
					$("#cm_template #filePicker_xsz" + (carDivCount - 1)).attr('id', "filePicker_xsz" + carDivCount);
					$("#cm_template #list_xsz" + (carDivCount - 1)).attr('id', "list_xsz" + carDivCount);
					$("#cm_template #filePicker_jsz" + (carDivCount - 1)).attr('id', "filePicker_jsz" + carDivCount);
					$("#cm_template #list_jsz" + (carDivCount - 1)).attr('id', "list_jsz" + carDivCount);
				}
				//车两管理
				node = $("#cm_template").html();
				var oTest = $("#carport_" + i);
				oTest.append(node);
	
				initWebUpload("filePicker_clbx" + carDivCount, "list_clbx" + carDivCount, "车辆保险", "carManage_articleId" + carDivCount, carSuccess, carErr);
				initWebUpload("filePicker_xsz" + carDivCount, "list_xsz" + carDivCount, "行驶证", "carManage_articleId" + carDivCount, carSuccess, carErr);
				initWebUpload("filePicker_jsz" + carDivCount, "list_jsz" + carDivCount, "驾驶证", "carManage_articleId" + carDivCount, carSuccess, carErr);
				//当刚开始这个div没有被展示 display=none时 这个div的宽高会为0，导致不能点击，所以要手动设置高度
				$("div[id^=filePicker] div").css({
					"width" : "65px",
					"height" : "30px"
				});
				//初始化下拉框
				if (isEdit == "yes") {
					initColorSelectData(carColor, carDivCount);
					initBrandSelectData(brandName, carDivCount);
					initCarTypeSelectData(carType, carDivCount);
				} else {
					initColorSelectData("", carDivCount);
					initBrandSelectData("", carDivCount);
					initCarTypeSelectData("", carDivCount);
				}
				carDivCount++;
			} else {
				//车位使用情况
				var carportType = $("#carportType").val();
				$("#ci_template #carUseType").text(carportType);
				node = $("#ci_template").html();
				node = node.replace(/jsu/, "usestaDate" + timeCount);
				node = node.replace(/jtr/, "useendDate" + timeCount);
				var oTest = $("#carport_" + i);
				oTest.append(node);
				oTest.find("input[name='usestaDate']").eq(timeCount).attr('id', "usestaDate" + timeCount);
				oTest.find("input[name='useendDate']").eq(timeCount).attr('id', "useendDate" + timeCount);
				timeCount++;
			}
		}
		var timeCount = 0;
		//存储将要删除的id，传到后台删除
		var delcarManIds = new Array();
		var delcarportIds = new Array();
		function delDiv1(obj, val) {
			var id = $(obj).parent().parent().parent().parent().find("input[name='id']").val();
			if (val == 1) {
				delcarManIds.push(id); //车辆信息
			} else {
				delcarportIds.push(id); //车位信息
			}
			$(obj).parent().parent().parent().parent().parent().remove();
			layer.msg("点击保存后，将彻底删除该条数据！");
		}
	</script>
</body>
<!-- 车俩信息模板div -->
<div id="cm_template" style="display:none;">
	<div style="border:1px solid gray;padding:10px;margin:10px">
		<table cellpadding="10" cellspacing="5" class="mytable">
			<tr height="45">
				<!-- 上传文件返回的附件id -->
				<input id="carManage_articleId" name="carManage_articleId"
					type="hidden" />
				<td width="90" class="right">使用人<input name="id"
					id="entityId_carId" type="hidden" /></td>
				<td width="260"><input name="usePeople" id="usePeople" value="" /></td>
				<td width="90" class="right">车型</td>
				<td width="260"><select class="js-example-basic-single"
					name="carManType" style="width:160px;">
						<option value="" selected="selected">请选择</option>
						<!--<option value="大型客车">大型客车</option>
						<option value="中型客车">中型客车</option>
						<option value="小型汽车">小型汽车</option>
						<option value="小型越野车">小型越野车</option>
						<option value="摩托车" >摩托车</option> -->
				</select></td>
				<td class="right">品牌名称</td>
				<td><select class="js-example-basic-single" name="brandName"
					style="width:160px;">
						<option value="" selected="selected">请选择</option>
				</select></td>
				<td valign="top" align="right"><a href="javascript:void(0)"
					onclick="delDiv1(this,'1')"> <i class="icon-fullscreen"></i>
				</a></td>
			</tr>
			<tr>
				<td width="90" class="right">颜色</td>
				<td><select class="js-example-basic-single" name="carColor"
					style="width:160px;">
						<option value="" selected="selected">请选择</option>
				</select></td>
				<td width="90" class="right">车牌号</td>
				<td colspan="2"><input name="carNumber" id="carNumber" /> <span></span>
				</td>

			</tr>
			<tr>
				<td width="90" class="right">车辆保险</td>
				<td width="260"><input name="carInsurance" id="carInsurance" />
					<div id='filePicker_clbx' >上传</div></td>
				<td width="90" class="right">行驶证</td>
				<td width="260"><input name="drivingLicense"
					id="drivingLicense" />
					<div id='filePicker_xsz' >上传</div></td>
				<td width="100" class="right">驾驶证</td>
				<td colspan="2"><input name="steerLicense" id="steerLicense" />
					<div id='filePicker_jsz' >上传</div></td>
			</tr>
			<tr>
				<!--车辆保险  用来显示缩略图 -->
				<td colspan="2">
					<div id='list_clbx'></div>
				</td>
				<!--行驶证  用来显示缩略图 -->
				<td colspan="2">
					<div id='list_xsz'></div>
				</td>
				<!--驾驶证 用来显示缩略图 -->
				<td colspan="3">
					<div id='list_jsz'></div>
				</td>
			</tr>
		</table>

	</div>
</div>
<!-- 车位模板div -->
<div id="ci_template" style="display:none;">
	<div style="border:1px solid gray;padding:10px;margin:10px">
		<table cellpadding="10" cellspacing="5" class="mytable">
			<tr>
				<td width="82"><b id="carUseType" name="carUseType">租赁：直租</b></td>
				<td width="50" class="right">位置<input name="id"
					id="entityId_carportId" type="hidden" /></td>
				<td width="185"><input name="carportLocation" /></td>
				<td width="70" class="right">车位号</td>
				<td><input name="carportNumber" /></td>
				<td width="70" class="right">期限</td>
				<td><input name="usestaDate" id="usestaDate" class="Wdate"
					onclick="WdatePicker({maxDate:'#F{$dp.$D(\'jtr\')}'})"
					readonly="readonly"> 至 <input name="useendDate"
					id="useendDate" class="Wdate"
					onclick="WdatePicker({minDate:'#F{$dp.$D(\'jsu\')}'})"
					readonly="readonly" /></td>
				<td width="70" class="right">价格说明</td>
				<td><input name="priceMsg" /></td>
				<td valign="top" align="right"><a href="javascript:void(0)"
					onclick="delDiv1(this,'2')"> <i class="icon-fullscreen"></i>
				</a></td>
			</tr>
		</table>
	</div>
</div>
</html>
